package cn.fl.spl.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.fl.capital.vo.CapChnOvdRateVO;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.framework.enums.FlowStartRelInfoCfgEnum;
import fl.spl.facade.framework.enums.SplRelLogBizTypCdNum;
import fl.spl.facade.spl.condition.SplHRiskWarnRecQC;
import cn.fl.spl.service.ISplHRiskWarnRecService;
import cn.fl.spl.vo.SplHRiskWarnRecVO;
import cn.fl.capital.condition.CapChnOvdRateQC;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.system.constant.SysLogConstant;
import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;

/**
 * @Description: 供应商高风险预警表 控制层
 */
@Controller
@RequestMapping("/spl/splHRiskWarnRec")
public class SplHRiskWarnRecController extends BaseController {

	/**
	 * SplHRiskWarnRec 服务层BEAN
	 */
	@Autowired
	private ISplHRiskWarnRecService splHRiskWarnRecService;
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	@Autowired
	private IFlowQueryApiService flowQueryApiService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("/spl/hRiskWarn/hRiskWarnList");
		
		List<KeyValueVO> splAttrCdList = this.sysDictionaryApiService.getKvList(DictionaryConstant.CODE_GRP_CST_TYP_CD, WebBaseConstant.SYS_SYS_CD, WebBaseConstant.SYS_P_ORG_CD);
		view.addObject("splAttrCdList", splAttrCdList);

		List<KeyValueVO> searchAudStsCdList = this.sysDictionaryApiService.getKvList(DictionaryConstant.CODE_AUD_STS_CD, WebBaseConstant.SYS_SYS_CD, WebBaseConstant.SYS_P_ORG_CD);
		view.addObject("searchAudStsCdList", searchAudStsCdList);

		return view;
	}
	
	/**
	 * 到复议流程列表页面
	 */
	@RequestMapping(value = "/toFlowListPage.do", method = { RequestMethod.GET})
	public ModelAndView toFlowListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("/spl/hRiskWarn/hRiskWarnFlowList");
		
		List<KeyValueVO> splAttrCdList = this.sysDictionaryApiService.getKvList(DictionaryConstant.CODE_GRP_CST_TYP_CD, WebBaseConstant.SYS_SYS_CD, WebBaseConstant.SYS_P_ORG_CD);
		view.addObject("splAttrCdList", splAttrCdList);

		List<KeyValueVO> searchAudStsCdList = this.sysDictionaryApiService.getKvList(DictionaryConstant.CODE_AUD_STS_CD, WebBaseConstant.SYS_SYS_CD, WebBaseConstant.SYS_P_ORG_CD);
		view.addObject("searchAudStsCdList", searchAudStsCdList);

		return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("/splHRiskWarnRec/modify");
		view.addObject("id", id);
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String dataNm = request.getParameter("dataNm");
		String dataAttrCd = request.getParameter("dataAttrCd");
		String audStsCd = request.getParameter("audStsCd");
		String rgnProvCd = request.getParameter("rgnProvCd");//区域-省
		String rgnCityCd = request.getParameter("rgnCityCd");//区域-市
		String dataTyp = request.getParameter("dataTyp");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		SplHRiskWarnRecQC qc = new SplHRiskWarnRecQC();
		if (StringUtils.isNotEmpty(dataNm)) {
			qc.setDataNm(dataNm);
		}
		if (StringUtils.isNotEmpty(dataAttrCd)) {
			qc.setDataAttrCd(dataAttrCd);
		}
		if (StringUtils.isNotEmpty(audStsCd)) {
			qc.setAudStsCd(audStsCd);
		}
		if (StringUtils.isNotEmpty(rgnProvCd)) {
			qc.setRgnPrCd(rgnProvCd);
		}
		if (StringUtils.isNotEmpty(rgnCityCd)) {
			qc.setRgnCyCd(rgnCityCd);
		}
		if (StringUtils.isNotEmpty(dataTyp)) {
			qc.setDataTyp(dataTyp);
		} else {
			qc.setDataTyp(SplRelLogBizTypCdNum.SPL.getBizTypCd());
		}
		qc.setFlowStatus(BaseConstant.IS_YESNO_NO_STR);
		qc.setIsDel(BaseConstant.IS_YESNO_NO);
		qc.setIsValid(BaseConstant.IS_YESNO_YES);
		qc.setIsWarn(BaseConstant.IS_YESNO_YES);
		
		page.setCondition(qc);

		Pager pager = this.splHRiskWarnRecService.searchListPage(page);
		if (null == pager){
			pager = new Pager();
		}
		List<SplHRiskWarnRecVO> list = (List<SplHRiskWarnRecVO>) pager.getResultList();
		ListPageVO<SplHRiskWarnRecVO> listPage = new ListPageVO<SplHRiskWarnRecVO>(list, pager.getTotalCount());
		BaseLogUtils.newWebLogger("查询数据完成. DATA:" + JSONObject.toJSONString(page)).setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();

		return listPage;
	}
	
	/**
	 * 初始化复议流程列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initFlowList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initFlowList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String dataNm = request.getParameter("dataNm");
		String dataAttrCd = request.getParameter("dataAttrCd");
		String audStsCd = request.getParameter("audStsCd");
		String rgnProvCd = request.getParameter("rgnProvCd");//区域-省
		String rgnCityCd = request.getParameter("rgnCityCd");//区域-市
		String dataTyp = request.getParameter("dataTyp");
		String flowStatus = request.getParameter("flowStatus");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		SplHRiskWarnRecQC qc = new SplHRiskWarnRecQC();
		if (StringUtils.isNotEmpty(dataNm)) {
			qc.setDataNm(dataNm);
		}
		if (StringUtils.isNotEmpty(dataAttrCd)) {
			qc.setDataAttrCd(dataAttrCd);
		}
		if (StringUtils.isNotEmpty(audStsCd)) {
			qc.setAudStsCd(audStsCd);
		}
		if (StringUtils.isNotEmpty(rgnProvCd)) {
			qc.setRgnPrCd(rgnProvCd);
		}
		if (StringUtils.isNotEmpty(rgnCityCd)) {
			qc.setRgnCyCd(rgnCityCd);
		}
		if (StringUtils.isNotEmpty(dataTyp)) {
			qc.setDataTyp(dataTyp);
		} else {
			qc.setDataTyp(SplRelLogBizTypCdNum.SPL.getBizTypCd());
		}
		if (StringUtils.isEmpty(flowStatus)) {
			qc.setFlowStatusList(Arrays.asList("1", "2"));
		} else {
			qc.setFlowStatus(flowStatus);
		}
		qc.setIsDel(BaseConstant.IS_YESNO_NO);
		qc.setIsValid(BaseConstant.IS_YESNO_YES);
		//qc.setIsWarn(BaseConstant.IS_YESNO_YES);
		
		page.setCondition(qc);

		Pager pager = this.splHRiskWarnRecService.searchListPage(page);
		if (null == pager) {
			pager = new Pager();
		}
		List<SplHRiskWarnRecVO> list = (List<SplHRiskWarnRecVO>) pager.getResultList();
		ListPageVO<SplHRiskWarnRecVO> listPage = new ListPageVO<SplHRiskWarnRecVO>(list, pager.getTotalCount());
		BaseLogUtils.newWebLogger("查询数据完成. DATA:" + JSONObject.toJSONString(page)).setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();

		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.splHRiskWarnRecService.removeById(Long.valueOf(id));
			BaseLogUtils.newWebLogger("删除数据.[id="+id+"]").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();

		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("删除数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("删除数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("获取数据,主键不存在.[id="+id+"]").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);

			return result;
		}
		
		try {
			SplHRiskWarnRecVO vo = this.splHRiskWarnRecService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.newWebLogger("获取数据,数据不存在.[id="+id+"]").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);

			}
			result.setData(vo);
			BaseLogUtils.newWebLogger("获取数据.[id="+id+"]").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();

		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("获取失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("获取失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		//String name = request.getParameter("name");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		SplHRiskWarnRecVO entity = null;
		try {
			entity = new SplHRiskWarnRecVO();
			//TODO ADD PARAM
			Long id = this.splHRiskWarnRecService.add(entity);
			result.setData(id);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
		}
		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		//String name = request.getParameter("name");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		SplHRiskWarnRecVO entity = null;
		try {
			entity = new SplHRiskWarnRecVO();
			entity.setId(Long.valueOf(id));
			//entity.setName(name);
			//TODO ADD PARAM
			boolean success = this.splHRiskWarnRecService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
		}
		return result;
	}
	
	/**
	 * 启动高风险复议流程
	 */
	@SuppressWarnings("deprecation")
	@RequestMapping(value = "/addFlowStart.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object addFlowStart(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String procDefKey = request.getParameter("procDefKey");
		String procDefId = request.getParameter("procDefId");
		String procNo = request.getParameter("procNo");
		String dataTyp = request.getParameter("dataTyp");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY).setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);

			return result;
		}
		//校验是否流程中
		SysFlowSHQueryCondition flowCondition = new SysFlowSHQueryCondition();
		flowCondition.setSysCd(SplSystemConstant.FL_SYS_CD);
		flowCondition.setWordsInTheTable(dataTyp.toUpperCase());
		flowCondition.setDataId(Long.valueOf(id));
		if (dataTyp.equalsIgnoreCase(FlowStartRelInfoCfgEnum.FLOW_LNK_RISK_WARN.getWordsInTheTable())) {
			flowCondition.setBusTyp(FlowStartRelInfoCfgEnum.FLOW_LNK_RISK_WARN.getModelTyp());
		}
		if (dataTyp.equalsIgnoreCase(FlowStartRelInfoCfgEnum.FLOW_SPL_RISK_WARN.getWordsInTheTable())) {
			flowCondition.setBusTyp(FlowStartRelInfoCfgEnum.FLOW_SPL_RISK_WARN.getModelTyp());
		}
		flowCondition.setStatus(BaseConstant.IS_YESNO_YES);
		List<SysFlowSHDTO> flowSHList = this.flowQueryApiService.searchFlowSHList(flowCondition);
		if(CollectionUtils.isNotEmpty(flowSHList)){
			//throw new BaseException(BaseExceptionConstant.COMMON_0001, "该供应商存在高风险复议流程，请不要重复发起.");
			if (!FlowConstant.FLOW_CHECK_STATE_PASS.equals(flowSHList.get(0).getAudStsCd())) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("该供应商存在高风险复议流程，请不要重复发起.");
				BaseLogUtils.newWebLogger("该供应商存在高风险复议流程，不能重复发起.").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);

				return result;
			}
		}
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			//流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);

			flowStartParamsDTO.setWordsInTheTable(dataTyp.toUpperCase());
			//流程定义标识(必填)
			flowStartParamsDTO.setProcDefKey(procDefKey);
			//流程定义ID(必填)
			flowStartParamsDTO.setProcDefId(procDefId);
			//流程定义名称(自定义)
			flowStartParamsDTO.setProcNo(procNo);

			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			//业务数据主键(必填)
			flowStartParamsDTO.setBusinessKey(id);
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
			//业务类型(必填)-用于区分操作表标识  确认用不用
			if (dataTyp.equalsIgnoreCase(FlowStartRelInfoCfgEnum.FLOW_SPL_RISK_WARN.getWordsInTheTable())) {
				flowStartParamsDTO.setBusinessType(FlowStartRelInfoCfgEnum.FLOW_SPL_RISK_WARN.getModelTypP());
				flowStartParamsDTO.setModelTyp(FlowStartRelInfoCfgEnum.FLOW_SPL_RISK_WARN.getModelTyp());//需要和流程配置中的模块类型匹配
			} else if (dataTyp.equalsIgnoreCase(FlowStartRelInfoCfgEnum.FLOW_LNK_RISK_WARN.getWordsInTheTable())) {
				flowStartParamsDTO.setBusinessType(FlowStartRelInfoCfgEnum.FLOW_LNK_RISK_WARN.getModelTypP());
				flowStartParamsDTO.setModelTyp(FlowStartRelInfoCfgEnum.FLOW_LNK_RISK_WARN.getModelTyp());//需要和流程配置中的模块类型匹配
			}
			//模块类型(流程业务分类): 针对直接启动流程的业务使用
			flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm()+"、流程大字段参数未定!");
			flowStartParamsDTO.setIsFlowStatePassCanbeStart(true);

			DataResultDTO dataResultDTO = this.splHRiskWarnRecService.addHRiskWarnFlowStart(flowStartParamsDTO);
			if(dataResultDTO != null){
				if(dataResultDTO.getCode() != null && !dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
				}
			}

		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.newWebLogger("启动高风险复议流程失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(e)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			e.getStackTrace();
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("启动高风险复议流程失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(e)
					.error(LogExceptionEnum.COMMON_CODE_0099);
			e.getStackTrace();
		}
		return result;
	}
	
	/**
	 * 初始化列表
	 */
	@RequestMapping(value = "/initCapChnOvdRateList.do", method = { RequestMethod.GET , RequestMethod.POST })
	@ResponseBody
	public Object initCapChnOvdRateList(HttpServletRequest request, HttpServletResponse response) {
		String dataId = request.getParameter("dataId");
		String dataTyp = request.getParameter("dataTyp");
		
		if (StringUtils.isEmpty(dataId)) {
			BaseLogUtils.newWebLogger("业务数据主键ID不能为空").error(LogExceptionEnum.COMMON_CODE_0001);
			throw new BaseException("业务数据主键ID不能为空");
		}
		
		if (StringUtils.isEmpty(dataTyp)) {
			BaseLogUtils.newWebLogger("业务数据类型不能为空").error(LogExceptionEnum.COMMON_CODE_0001);
			throw new BaseException("业务数据类型不能为空");
		}

		CapChnOvdRateQC qc = new CapChnOvdRateQC();
		if (StringUtils.isNotEmpty(dataTyp)) {
			if (dataTyp.equalsIgnoreCase(SplRelLogBizTypCdNum.SPL.getBizTypCd())) {
				qc.setChnTypCd("1");
			} else if (dataTyp.equalsIgnoreCase(SplRelLogBizTypCdNum.LNK.getBizTypCd())) {
				qc.setChnTypCd("2");
			}
		}
		qc.setChnId(Long.valueOf(dataId));
		
		List<CapChnOvdRateVO> list = this.splHRiskWarnRecService.searchCapChnOvdRateList(qc);
		if (CollectionUtils.isEmpty(list)) {
			list = new ArrayList<>();
		}
		ListPageVO<CapChnOvdRateVO> listPage = new ListPageVO<CapChnOvdRateVO>(list, list.size());
		BaseLogUtils.newWebLogger("查询数据完成. DATA:" + JSONObject.toJSONString(list)).setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();

		return listPage;
	}
	
}

